package cn.psvmc.cxzapi.service.customer;

import cn.psvmc.cxzapi.config.mybatisplus.service.impl.AbstractService;
import cn.psvmc.cxzapi.mapper.customer.TCustomerGoodsRecordMapper;
import cn.psvmc.cxzapi.model.customer.TCustomerGoodsRecord;
import cn.psvmc.cxzapi.service.system.ServiceUtil;
import cn.psvmc.cxzapi.util.ToolUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 客户商品浏览记录表 服务实现类
 *
 * @Author auto
 * @Date 2024-08-27
 */
@Service
public class TCustomerGoodsRecordService extends AbstractService<TCustomerGoodsRecordMapper, TCustomerGoodsRecord> {

    @Resource
    private TCustomerGoodsRecordMapper tCustomerGoodsRecordMapper;
    @Resource
    private ServiceUtil serviceUtil;

    /**
     * @Description 添加记录
     * @Date 2024/8/27 22:05
     * @Author YWX
     * @Param [tCustomerGoodsRecord]
     * @Return int
     **/
    public void add(TCustomerGoodsRecord tCustomerGoodsRecord) {
        Integer customerId = serviceUtil.getCustomerIdNoCheck();
        if (!ToolUtils.isTrueInteger(customerId)) return;
        if (serviceUtil.getCustomerNoCheck(customerId) == null) return;
        tCustomerGoodsRecordMapper.insert(tCustomerGoodsRecord);
    }

    /**
     * @Description 记录列表
     * @Date 2024/8/27 21:57
     * @Author YWX
     * @Param [iPage]
     * @Return com.baomidou.mybatisplus.core.metadata.IPage<java.util.Map < java.lang.String, java.lang.Object>>
     **/
    public IPage<Map<String, Object>> list(Page<TCustomerGoodsRecord> iPage) {
        return tCustomerGoodsRecordMapper.listByCustomerId(iPage, serviceUtil.getCustomerId());
    }
}
